package cn.easybuy.web.backend;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.easybuy.entity.User;
import cn.easybuy.service.UserService;
import cn.easybuy.service.impl.UserServiceImpl;
import cn.easybuy.util.Page;

public class UserServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String action=request.getParameter("action");
		UserService us=new UserServiceImpl();
		User user=new User();
		PrintWriter out=response.getWriter();
		if (action.equals("showUser")) {
			Page page=new Page();
			int totalCount=us.getTotalCount();
			String currNo=request.getParameter("currNo");
			if (currNo==null||currNo=="") {
				currNo="1";
			}
			page.setCurrentPageNumber(Integer.parseInt(currNo));
			page.setPageSize(10);
			page.setTotalCount(totalCount);
			List<User> list=us.getUsersPage(Integer.parseInt(currNo), page.getPageSize());
			page.setUsersList(list);
			String userJSON=JSON.toJSONString(page);
			out.print(userJSON);
			
			
		}
		out.flush();
		out.close();
		
		
	}

}
